package com.zs.controller;


import com.mzt.logapi.starter.annotation.LogRecord;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zs.service.DemoUserService;
import com.zs.common.dto.DemoUserDTO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.Valid;

/**
 * Copyright 2020 ZS Network Co., Ltd. All rights reserved.
 * 本文件仅限于正数网络技术有限公司内部传阅，禁止外泄以及用于其他的商业目的。
 * Created by yuancong on 2022-12-02.
 */
@RestController
@RequestMapping("/demoUser")
@Validated
@Slf4j
public class DemoUserController {
    @Autowired
    private DemoUserService  demoUserService;

    @GetMapping("/{id}")
    public DemoUserDTO getEntity(@PathVariable("id") String id) {
        log.info("demo user:{}", id);
        log.info("demo user2:{}", id);
        return demoUserService.get(id);
    }

    @LogRecord(success = "新增用户：{{#record.name}}",
            type = "addUser",subType = "",bizNo = "{{#record.name}}",extra = "")
    @PostMapping("/add")
    public boolean addEntity(@Valid @RequestBody DemoUserDTO record) {
        return demoUserService.insert(record);
    }

    @PutMapping("/update")
    public boolean updateEntity(@Valid @RequestBody DemoUserDTO record) {
        return demoUserService.update(record);
    }

    @GetMapping("/list")
    public Page<DemoUserDTO> pageList(@Min(1) @RequestParam Integer pageNum,@Min(1) @Max(1000) @RequestParam Integer pageSize) {
        return demoUserService.pageList(pageNum, pageSize);
    }
}